package compilers.condition;

import java.io.BufferedWriter;
import java.io.IOException;

import compilers.node.Identifier;
import compilers.stmt.Condition;
import compilers.table.MemScope;
import compilers.types.Type;

public class Param extends Condition {

	Condition fType;
	
	public Param(Condition fType, Identifier fIdentifier) {
		super();
		this.fType = fType;
		if (fType instanceof Type) {
			Type t = (Type)fType;
			t.setfIdentifier(fIdentifier);
		}
	}

	public Param(Condition fType) {
		super();
		this.fType = fType;
	}

	public void addIdentifier(Identifier fIdentifier) {
		if (fType instanceof Type) {
			Type t = (Type)fType;
			t.setfIdentifier(fIdentifier);
		}
	}
	
	public Type getType() {
		if (fType instanceof Type) {
			Type t = (Type)fType;
			return t;
		}
		return null;
	}
	
	public void setType(Type t) {
		fType = t;
	}
	
	public Identifier getIdentifier() {
		if (fType instanceof Type) {
			Type t = (Type)fType;
			return t.getfIdentifier();
		}
		return null;
	}

	public void print(int tab) {
		for (int i=1;i<=tab;i++){System.out.print("\t");}System.out.print("|-");
		System.out.println("Param");
		fType.print(tab+1);
	}

	public void generate(BufferedWriter writer, MemScope scope) throws IOException {
		fType.setfRes(this.getfRes());
		fType.generate(writer, scope);
	}

}
